package com.myinternet.lutu.controller;

import com.myinternet.lutu.modal.LessJsonResult;
import com.myinternet.lutu.pojo.AccessList;
import com.myinternet.lutu.service.AccessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RequestMapping("access")
@RestController
public class AccessController {

    @Autowired
    private AccessService accessService;

    @RequestMapping("/saveAccess")
    private LessJsonResult saveAccess() {
        AccessList accessList = new AccessList();
        accessList.setAccessIp("192.168.31.1111");
        accessList.setAccessTime(new Date());
        accessService.saveAccess(accessList);
        return LessJsonResult.ok("保存成功");
    }

    @RequestMapping("/updateAccess")
    private LessJsonResult updateAccess() {
        AccessList accessList = new AccessList();
        accessList.setAccessId(74);
        accessList.setAccessIp("192.168.31.12");
        accessList.setAccessTime(new Date());
        accessService.updateAccess(accessList);
        return LessJsonResult.ok("修改成功");
    }

    @RequestMapping("/delAccess")
    private LessJsonResult delAccess() {
        AccessList accessList = new AccessList();
        accessService.deleteAccess(74);
        return LessJsonResult.ok("删除成功");
    }

    @RequestMapping("/queryAccess")
    private LessJsonResult queryAccessById() {
        return LessJsonResult.ok(accessService.queryAccessById(73));
    }

    @RequestMapping("/queryAllAccess")
    private LessJsonResult queryAllAccess() {
        return LessJsonResult.ok(accessService.queryAllAccess());
    }

    @RequestMapping("/queryUserListPaged")
    public LessJsonResult queryUserListPaged(Integer page) {
        if (page == null) {
            page = 1;
        }
        int pageSize = 10;
        AccessList accessList = new AccessList();
        List<AccessList> userList = accessService.queryAccessPaged(accessList, page, pageSize);
        return LessJsonResult.ok(userList);
    }
}
